package com.jike.shop.cloud.controller;

import com.google.gson.Gson;
import com.jike.shop.cloud.constant.ApiConstants;
import com.jike.shop.cloud.service.OrderService;
import com.jike.shop.common.dto.CreateOrderDTO;
import com.jike.shop.common.message.Replys;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping(ApiConstants.API_VERSION + "/order")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/preCreate")
    public long preCreateOrder() {
        return orderService.preCreateOrder();
    }



    @PostMapping("/create")
    //@AccessLimit
    public ResponseEntity<Replys<String>> createOrder(@RequestBody CreateOrderDTO requestDTO, HttpServletRequest request) {
        log.debug("创建订单：【{}】", new Gson().toJson(requestDTO));
        return Replys.ok(orderService.createOrder(requestDTO));
    }

    public void payOrder() {

    }

    @GetMapping("/test/{orderId}")
    public ResponseEntity<Replys<String>> test(@PathVariable("orderId") String orderId){
        CreateOrderDTO createOrderDTO = CreateOrderDTO.builder().orderId(Long.parseLong(orderId)).build();
        return Replys.ok(orderService.createOrder(createOrderDTO));
    }
}

